#include "../../client/rpc_client.hpp"
#include <thread>

void callback(const Json::Value &result)
{
    ILOG("result:%d", result.asInt());
}
int main()
{

    Json_rpc::client::RpcClient client(true, "127.0.0.1", 8888);

    // 同步测试
    {
        Json::Value params, result;
        params["num1"] = 11;
        params["num2"] = 22;
        bool ret = client.call("Add", params, result);
        if (ret != false)
        {
            ILOG("result:%d", result.asInt());
        }
    }

    // //异步测试
    {
        Json::Value params, result;
        Json_rpc::client::RpcCaller::JsonAsyncResponse res_future;
        params["num1"] = 33;
        params["num2"] = 44;
        bool ret = client.call("Add", params, res_future);
        if (ret != false)
        {
            result = res_future.get();
            ILOG("result:%d", result.asInt());
        }
    }

    // 回调测试
    {
        Json::Value params, result;
        Json_rpc::client::RpcCaller::JsonResponseCallback func = [](const Json::Value &val)
        { ILOG("result:%d", val.asInt()); };
        params["num1"] = 44;
        params["num2"] = 55;
        bool ret = client.call("Add", params, func);
    }

    std::this_thread::sleep_for(std::chrono::seconds(5));

    return 0;
}